{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}

{% block title %}语音识别模型基准测试系统{% endblock %}

{% block page_content %}
<div class="page-header">
    {% if kw %}
    <p>{{ kw }}搜索结果共有{{ test_projects.total }}条测试项目数据项</p>
    <a class="btn btn-default" href="{{ url_for('.test_project') }}">查看所有测试项目信息</a>
    {% else %}
    <p>目前共有{{ test_projects.total }}条测试项目数据项</p>
    <a class="btn btn-default" href="{{ url_for('.test_project_add') }}">新增测试项目信息</a>
    {% endif %}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" id="kw-input" onkeyup="update_action(event,this.value);" value="{{ kw }}">
    <a class="btn btn-default" id="search-a" href="{{ url_for('.test_project_search',kw='') }}">搜索</a>
    {% if test_projects.first==0 %}
    <p>没有{% if kw %}含有{{ kw }}的{% endif %}测试项目信息</p>
    {% else %}
    <div class="row">
    <table class="table">
        <thead>
        <tr>
            <th>名称</th>
            <th>语音识别模型</th>
            <th>语音的前端处理器（+特征提取器）</th>
            <th>语音的特征提取器</th>
            <th>模型的训练数据预处理器</th>
            <th>模型的验证数据预处理器</th>
            <th>模型的测试数据预处理器</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {% for i in range(test_projects.items|length) %}
        <tr>
            <td class="content-td">{{ test_projects.items[i].name }}</td>
            <td><a href="{{ url_for('.m',id=models[i].id) }}">{{ models[i].name }}</a></td>
            <td>
                <a href="{{ url_for('.ff',id=fps[i].id) }}">{{ fps[i].name }}</a>
            </td>
            <td>{% if fes[i] %}<a href="{{ url_for('.ff',id=fes[i].id) }}">{{ fes[i].name }}</a>{% else %}-{% endif %}</td>
            <td>{% if train_dps[i] %}<a href="{{ url_for('.dp',id=train_dps[i].id) }}">{{ train_dps[i].name }}</a>{% else %}-{% endif %}</td>
            <td>{% if val_dps[i] %}<a href="{{ url_for('.dp',id=val_dps[i].id) }}">{{ val_dps[i].name }}</a>{% else %}-{% endif %}</td>
            <td>{% if test_dps[i] %}<a href="{{ url_for('.dp',id=test_dps[i].id) }}">{{ test_dps[i].name }}</a>{% else %}-{% endif %}</td>
            <td>
                <a class="btn btn-default" href="{{ url_for('.test_project_delete',id=test_projects.items[i].id,page=page,per_page=per_page) }}">删除</a>
                <a class="btn btn-default" href="{{ url_for('.tp',id=test_projects.items[i].id) }}">查看详情</a>
                <a class="btn btn-default" href="{{ url_for('.test_project_active',id=test_projects.items[i].id) }}">更新活动时间</a>
                <a class="btn btn-default" href="{{ url_for('.test_project_copy',id=test_projects.items[i].id) }}">以此为模版新建</a>
            </td>
        </tr>
        {% endfor %}
        </tbody>
        <tfoot>
            {% if kw %}
            <tr>
                <td colspan="4">
                    <ul class="pagination">
                        {% for i in page_range %}
                        {% if i==test_projects.page %}
                        <li class="active"><a href="/test_project_search?page={{ i }}&per_page={{ per_page }}&kw={{ kw }}">{{ i }}</a></li>
                        {% else %}
                        <li><a href="/test_project_search?page={{ i }}&per_page={{ per_page }}&kw={{ kw }}">{{ i }}</a></li>
                        {% endif %}
                        {% endfor %}
                    </ul>
                </td>
                <td colspan="4" style="vertical-align:bottom">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">当前每页{{ per_page }}条数据项，更改至每页数据项 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            {% for i in [5,10,20,50] %}
                            <li><a href="/test_project_search?page=1&per_page={{ i }}&kw={{ kw }}">{{ i }}条</a></li>
                            {% endfor %}
                        </ul>
                    </li>
                </td>
            </tr>
            {% else %}
            <tr>
                <td colspan="4">
                    <ul class="pagination">
                        {% for i in page_range %}
                        {% if i==test_projects.page %}
                        <li class="active"><a href="/test_project?page={{ i }}&per_page={{ per_page }}">{{ i }}</a></li>
                        {% else %}
                        <li><a href="/test_project?page={{ i }}&per_page={{ per_page }}">{{ i }}</a></li>
                        {% endif %}
                        {% endfor %}
                    </ul>
                </td>
                <td colspan="4" style="vertical-align:bottom">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">当前每页{{ per_page }}条数据项，更改至每页数据项 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            {% for i in [5,10,20,50] %}
                            <li><a href="/test_project?page=1&per_page={{ i }}">{{ i }}条</a></li>
                            {% endfor %}
                        </ul>
                    </li>
                </td>
            </tr>
            {% endif %}
        </tfoot>
    </table>
</div>
    {% endif %}
    <p id="kw-value" style="display:none">{{ kw }}</p>
<script type="text/javascript">
    function update_action(event,s){
        if(s.length!=0){
            old_href=$('#search-a').attr('href');
            $('#search-a').attr('href',old_href.replace(new RegExp('\\?kw\\=[^&]*','gi'),'?kw='+s));
            if(event.key=='Enter'){
                window.location.href=$('#search-a').attr('href');
            }
        }
    }
</script>
{% if kw %}
<script type="text/javascript">
    $(document).ready(function(){
        var query=$('#kw-value').text();
        var content_tds=document.getElementsByClassName('content-td');
        var regex=new RegExp(query,'gi');
        for(let i=0;i<content_tds.length;i++){
            content_tds[i].innerHTML=content_tds[i].innerHTML.replace(regex,'<font style="color:red;">$&</font>');
        }
    });
</script>
{% endif %}
</div>

{% endblock %}